<?php
namespace app\models;

use think\Model;
use app\models\Region;

class Invest extends Model
{
    protected $pk = 'id';
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'created';
    protected $addend = ['invest_text','region_text','region_name'];

    public function getInvestTextAttr($value,$data){
        if(isset($data['invest_id'])){
            return config('base.invest')[$data['invest_id']];
        }
    }

    public function getRegionTextAttr($value,$data){
        if(isset($data['region_id'])){
            return Region::get(['id'=>$data['region_id']])['rate'];
        }
    }

    public function getRegionNameAttr($value,$data){
        if(isset($data['region_id'])){
            $region = Region::get(['id'=>$data['region_id']]);
            return $region['country'].' '.$region['area'];
        }
    }

}